package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.sl.au.entity.InventoryReduce;
import com.sl.au.repository.InventoryReduceRepository;
import com.sl.au.repository.QuoteDeviceRepository;
import com.sl.au.service.InventoryReduceService;

@Service("InventoryReduceService")
public class InventoryReduceServiceImpl extends BaseServiceImpl implements InventoryReduceService {

	@Autowired 
	InventoryReduceRepository inventoryReduceRepository;
	@Autowired
	QuoteDeviceRepository quoteDeviceRepository;
	
	@Override
	public InventoryReduceRepository getRepository() {
		return this.inventoryReduceRepository;
	}
	@Override
	public QuoteDeviceRepository getDeviceRepository() {
		return this.quoteDeviceRepository;
	}

	@Override
	public List<InventoryReduce> getInventoryReduce(int start, int length, String key, String orderName, String dir) {
		Page<InventoryReduce> pages=null;
		Pageable pageable = new PageRequest(start / length, length, Sort.Direction.DESC, "createTime");
		if(StringUtils.hasText(key)){
			pages=inventoryReduceRepository.findInventoryReduce(key,pageable);
		}
		else{
			pages=inventoryReduceRepository.findAll(pageable);
		}
		return pages.getContent();
	}

	@Override
	public List<InventoryReduce> getQuoteIsReplace(int start, int length, String quoteDeviceId, String orderName,
			String dir) {
		Page<InventoryReduce> pages=null;
		Pageable pageable = new PageRequest(start / length, length, Sort.Direction.DESC, "createTime");
		pages=inventoryReduceRepository.getIsReplace(quoteDeviceId,pageable);
		return pages.getContent();
	}


}
